

package com.hazelcast.client;

import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.impl.clientside.ClientConnectionManagerFactory;
import com.hazelcast.client.impl.connection.AddressProvider;
import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.core.HazelcastInstance;

public class HazelcastClientUtil {

    public static HazelcastInstance newHazelcastClient(ClientConfig config, AddressProvider addressProvider) {
        return HazelcastClient.newHazelcastClientInternal(config, null, null, addressProvider);
    }

    public static HazelcastInstance newHazelcastClient(ClientConfig config, ClientConnectionManagerFactory connectionManagerFactory, AddressProvider addressProvider) {
        return HazelcastClient.newHazelcastClientInternal(config, null, connectionManagerFactory, addressProvider);
    }

    public static ClientMessage.Frame fastForwardToEndFrame(ClientMessage.ForwardFrameIterator iterator) {
        int numberOfExpectedEndFrames = 1;
        ClientMessage.Frame frame = null;
        while (numberOfExpectedEndFrames != 0) {
            frame = iterator.next();
            if (frame.isEndFrame()) {
                numberOfExpectedEndFrames--;
            } else
                if (frame.isBeginFrame()) {
                    numberOfExpectedEndFrames++;
                }
        }
        return frame;
    }
}
